package com.mate.cloud.sensitive.processor;

import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;
import lombok.Data;

@Data
public class RSAProcessor  implements SecurityProcessor {

    private String publicKey;

    private String privateKey;

    private RSA rsa;

    public RSAProcessor(String publicKey, String privateKey) {
        this.publicKey = publicKey;
        this.privateKey = privateKey;
        this.rsa = new RSA(privateKey, publicKey);
    }



    @Override
    public byte[] encrypt(byte[] data) {
        return rsa.encrypt(data,KeyType.PublicKey);
    }
    @Override
    public byte[] decrypt(String text) {
        return rsa.decrypt(text,KeyType.PrivateKey);
    }
}
